package io.openkunlun.examples.springboot.provider;

import io.openkunlun.javadsl.client.DaprClient;
import io.openkunlun.javadsl.server.FailureDetected;
import io.openkunlun.javadsl.server.FailureDetector;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadLocalRandom;

@Configuration
public class RpcFailureDetector implements FailureDetector {

    @Override
    public FailureDetected detect(DaprClient client) {
        int random = ThreadLocalRandom.current().nextInt(100);
        if (random >= 95) {
            return FailureDetected.UNAVAILABLE;
        } else {
            return FailureDetected.AVAILABLE;
        }
    }
}
